<?php

namespace App\Models\base\traits;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;

trait HasOwner
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * @param Builder $builder
     * @param int $userId
     * @return Builder
     */
    public function scopeOwner(Builder $builder, int $userId)
    {
        return $builder->where('user_id', $userId);
    }
}
